<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app">
        <my-cpn></my-cpn>
        <my-cpn></my-cpn>
        <my-cpn></my-cpn>
        <my-cpn></my-cpn>
        <my-cpn-two ref="dataRef"></my-cpn-two>
        <my-cpn ref="cpnRef"></my-cpn>
        <my-cpn></my-cpn>
        <my-cpn></my-cpn>
        <button @click="getData">点击获取子组件的数据</button>
    </div>
    <script src="../js/vue.js"></script>

    <template id="mycpn">
        <div>{{ msg }}</div>
    </template>

    <template id="mycpntwo">
        <div>{{ msg }}</div>
    </template>

    <script>
        const app = new Vue({
            el:"#app",
            data(){
                return {

                }
            },
            components:{
                'my-cpn':{
                    template:'#mycpn',
                    data(){
                        return {
                            msg:'我是组件中的数据'
                        }
                    }
                },
                'my-cpn-two':{
                    template:'#mycpntwo',
                    data(){
                        return {
                            msg:'第二个组件中的数据'
                        }
                    }
                }
            },
            methods:{
                getData(){
                    console.log(this.$refs.dataRef.msg)
                    // console.log(this.$children[4].msg)
                }
            }
        })
    </script>
</body>
</html>